﻿using System;
using System.Text;
using System.Web.UI;
using PowerToolsWeb.DataAccess;

namespace PowerToolsWeb
{
    public partial class Message : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (this.txbName.Text.Trim() == "")
            {
                Alert(Page, "请输入您的姓名");
                return;
            }
            if (txbTel.Text.Trim() == "")
            {
                Alert(Page, "请输入你的联系电话");
                return;
            }
            Tpt_Message message = new Tpt_Message();
            message.COMPANY = txbCompany.Text.Trim();
            message.NAME = txbName.Text.Trim();
            message.PHONE = txbTel.Text.Trim();
            message.EMAIL = txbEMail.Text.Trim();
            message.TITLE = TxbTitle.Text.Trim();
            message.CONTENT = txbConnent.Text.Trim();
            message.ISREAD = false;
            message.ISDELETE = false;
            if (!message.Insert())
            {
                Alert(Page, "对不起，发送留言出错，请重新操作！");
                return;
            }
            Alert(Page, "留言成功！我们会尽快给您答复，谢谢！");
        }

        /// <summary>
        /// 弹出客户端警告对话框。模拟javascript的alert
        /// </summary>
        /// <param name="Page">当前的页面的 Page 类，在调用时用 Page 就行了</param>
        /// <param name="msg">要弹出的字符串</param>
        /// <returns> 无返回值</returns>
        public static void Alert(Page Mypage, string msg)
        {
            if (msg == null) return;
            string tempstr = msg.Replace("\"", "\\\"");
            tempstr = tempstr.Replace("\'", "\\\'").Replace("\n", "").Replace("\r", "");
            StringBuilder sb = new StringBuilder("<script Language=\"Javascript\">");
            sb.Append("alert(\"");
            sb.Append(tempstr).Append("\");");
            sb.Append("<").Append("/").Append("script>");

            if (!Mypage.ClientScript.IsStartupScriptRegistered("msgscript"))
                Mypage.ClientScript.RegisterStartupScript(Mypage.GetType(), "msgscript", sb.ToString());
        }
    }
}
